#include "switchbuttom.h"

switchbuttom::switchbuttom() {}

void switchbuttom::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing,true);
    painter.setPen(Qt::NoPen);
    painter.setBrush(switchbtn?onbrush:offbrush);
    painter.drawRoundedRect(this->rect(),height()/2,height()/2);

    painter.setBrush(switchbtn?onindicator:offindicator);
    QPoint center;
    switchbtn?center=QPoint(width()-height()/2,height()/2):center=QPoint(height()/2,height()/2);
    painter.drawEllipse(center,height()/2,height()/2);
}

void switchbuttom::mousePressEvent(QMouseEvent *event)
{
    if(event->button()==Qt::LeftButton)
    {
        switchbtn=!switchbtn;
        emit clicked(switchbtn);
        update();
    }
}

void switchbuttom::Getswitchbtnvalue(bool btn_status)
{
    this->switchbtn=btn_status;
    update();
    emit clicked(this->switchbtn);
    //status_toggle();
}

